package entity

import (
	"shqsoft.cn/pasnj/base"

	"github.com/jinzhu/gorm"
)

//恒生理财
type INDI_HSLC struct {
	ID    int    `gorm:"AUTO_INCREMENT;primary_key;column:ID"`
	JYLSH string `gorm:"column:JYLSH"`
	QRRQ  string `gorm:"column:QRRQ;"`
	KHJL  string `gorm:"column:KHJL;"`
}

//TableName 表名
func (INDI_HSLC) TableName() string {
	return "T_INDI_HSLC"
}

//AfterCreate 插入后的触发器
func AfterImport(tx *gorm.DB, params map[string]string) (err error) {
	err = tx.Exec("UPDATE T_INDI_HSLC SET EMID =B.ID FROM T_INDI_HSLC A LEFT JOIN T_SysUser B ON A.KHJL=B.SysUserID WHERE A.KHJL<>'000000' OR A.KHJL IS NOT NULL").Error
	if err != nil {
		return err
	}
	err = tx.Exec("UPDATE f_fin_his_tbtransreq SET client_manager =B.KHJL FROM f_fin_his_tbtransreq A LEFT JOIN T_INDI_HSLC B ON A.serial_no=B.JYLSH AND A.cfm_date=CAST(REPLACE(REPLACE(QRRQ,'/',''),'-','') AS INT) ").Error
	if err != nil {
		return err
	}
	return nil
}

func INDI_HSLCEF() base.EntityFunc {
	return func() interface{} {
		entity := INDI_HSLC{}
		return &entity
	}
}
func INDI_HSLCESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []INDI_HSLC
		return &entities
	}
}

func init() {
	base.DaoPoolObj.Put("INDI_HSLC", base.NewDefaultDao(INDI_HSLCEF(), INDI_HSLCESF(), nil))
	base.SetAfterCallBack("INDI_HSLC", AfterImport)
}
